package com.koron.css2.baseConfig.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.bean.MeterStatusBean;
import com.koron.css2.baseConfig.mapper.MeterStatusMapper;
import com.koron.css2.baseConfig.vo.SelectVO;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;
/**
 * 抄表状态-下拉框
 * @author 许海宜
 *
 */
public class MeterStatusSelect implements ServerInterface  {
	
	private static Logger logger = LogManager.getLogger(MeterStatusSelect.class);

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		@SuppressWarnings("rawtypes")
		MessageBean<List> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", List.class);
		try {
			MeterStatusBean bean = JsonUtils.objectToPojo(req.getData(), MeterStatusBean.class);
			if(bean.getAbnormalFlag() == null) {
				info.setCode(Constant.MESSAGE_INT_FAIL);
				info.setDescription("异常类型不能为空。");
				return info;
			}
			MeterStatusMapper mapper = factory.getMapper(MeterStatusMapper.class);	
			List<SelectVO> list = mapper.selectComboBox(bean.getAbnormalFlag());			
			info.setData(list);
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription("查询抄表状态失败");
			logger.error(e.getMessage(), e);
		}
		return info;
	}

}